/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.osdtsystem.functions;

import java.util.List;
import org.osdtsystem.graphs.GraphAccessor;

/**
 *
 * @author matthias
 */
public class FuncSize extends AbstractSingletonFunction<Integer> {
    Function<?> subfunction;

    FuncSize(Function<?> subfunction) {
        super(subfunction);
        this.subfunction = subfunction;
    }

    @Override
    public Integer _singletonFunctionValue(LocalFunction<?, ?> caller, FunctionContext context,
            GraphAccessor accessor) {
        List<?> list = subfunction.functionValue(caller, context, accessor);
        return list != null ? list.size() : 0;
    }

    @Override
    void toStringBuilder(FunctionStringBuilder builder) {
        builder.addSubfunction(subfunction);
    }
}
